// 模拟的文物数据分类
const categories = ['所有', '青铜器', '陶瓷器', '书画', '玉器'];

// 图片和视频数据
const imageUrls2 = [
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/3a372965-37a6-469a-b252-489c5f04bbb7.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/a0f9e903-186f-46a8-9d3c-1e0d02e63b22.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/e066253e-8f31-4ce7-82bd-b288a2f439b6.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/a344c0b1-48d0-41a0-8278-4687086cfe01.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/baa26b21-b508-489c-8439-6e79f8ab86b9.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/d7c4a175-540c-42ba-b3e7-02fa3713df8a.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/d88deff0-5275-42c3-a023-7c8f2fb1dce1.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/d6fc9f64-0454-4ffe-8b29-11df72447341.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/65ef0620-f2f1-4342-9d57-e9c5580f42ef.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/d3d90a78-b043-4656-b35f-e190da92c848.jpg',
];

const imageUrls3 = [
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/a8b4d86e-3589-4415-93f1-4ea4f29842fc.png_290xaf.png',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/bcb9c0bf-dde5-43b0-ac49-e9ce7dc367fa.png_290xaf.png',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/937553a5-82e1-4a01-87b5-346db104d9e9.png_290xaf.png',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/5b54ccc3-3299-4523-87e2-55ddc1501ce4.png_290xaf.png',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/ec946a0b-eb51-41cf-8c9b-07418fe7cf18.jpg_290xaf.jpg',
  'https://omo-oss-image.thefastimg.com/portal-saas/new2023031518242917793/cms/image/5b54ccc3-3299-4523-87e2-55ddc1501ce4.png'
];

const videoUrls = [
  "https://www.w3schools.com/html/mov_bbb.mp4"
];



const titles = [
  '博物馆新展览开幕',
  '纪念日活动回顾',
  // ... 其他标题
];

// 随机生成日期
const getRandomDate = () => {
  const start = new Date(2024, 0, 1);
  const end = new Date(2024, 11, 31);
  const randomTime = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
  return randomTime.toISOString().split('T')[0];
};

// 动态数据列表
const dynamicList = [];

const result = [];
// 生成动态新闻数据
const generateDynamicNews = (count = 5) => {
  for (let i = 0; i < count; i++) {
    const dynamicNews = {
      id: i + 1, // 添加 ID
      title: titles[Math.floor(Math.random() * titles.length)], // 随机标题
      content: `这是动态新闻内容 ${i + 1} 的详细描述。`, // 添加 content
      date: getRandomDate(), // 随机日期
      imageUrl2: imageUrls3[Math.floor(Math.random() * imageUrls3.length)], // 随机图片
      videoUrl: videoUrls[Math.floor(Math.random() * videoUrls.length)], // 随机视频链接
    };
    dynamicList.push(dynamicNews); // 保存到动态列表
    result.push(dynamicNews); // 返回的结果
  }
  return result;
};

// 获取动态新闻接口
const getDynamicNews = ({ page = 1, pageSize = 10 } = {}) => {
  // 确保数据存在
  if (dynamicList.length === 0) {
    generateDynamicNews(5); // 预先生成 50 条动态数据
  }

  // 分页处理
  const total = dynamicList.length;
  const startIndex = (page - 1) * pageSize;
  const paginatedData = dynamicList.slice(startIndex, startIndex + pageSize);

  return {
    data: paginatedData,
    total,
  };
};

// 文物数据初始化
const mockData = [];
for (let i = 1; i <= 50; i++) {
  mockData.push({
    id: i,
    title: `历史${i}`,
    description: `这是侵华日军第七三一部队旧址城子沟野外实验场遗址${i}的简短描述。`,
    category: categories[Math.floor(Math.random() * categories.length)],
    imageUrl: imageUrls2[Math.floor(Math.random() * imageUrls2.length)],
    imageUrl2: imageUrls3[Math.floor(Math.random() * imageUrls3.length)],
    videoUrl: videoUrls[Math.floor(Math.random() * videoUrls.length)],
  });
}

// 获取文物数据并支持分页与过滤
const getArtifacts = ({ page = 1, pageSize = 10, category = '所有', query = '' } = {}) => {
  let filteredData = mockData;

  // 分类过滤
  if (category !== '所有') {
    filteredData = filteredData.filter((item) => item.category === category);
  }

  // 搜索过滤
  if (query) {
    filteredData = filteredData.filter((item) =>
      item.title.includes(query) || item.description.includes(query)
    );
  }

  // 分页处理
  const total = filteredData.length;
  const startIndex = (page - 1) * pageSize;
  return {
    data: filteredData.slice(startIndex, startIndex + pageSize),
    total,
  };
};

// 根据 ID 获取单条数据（文物或新闻）
const getItemById = (id) => {

  return mockData.find((item) => item.id == id) || null;
};

// 导出模块
module.exports = {
  getArtifacts,
  categories,
  generateDynamicNews,
  getDynamicNews, // 新增接口
  getItemById,
};
